package com.sjtu.web.config;

import com.google.gson.Gson;
import com.sjtu.web.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * nerine
 * 2/4/2020
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
    @Autowired
    private Gson gson;

    @ExceptionHandler(Throwable.class)
    @ResponseBody
    public Result<?> springHandleNotFound(Throwable throwable) {
        log.error("system error:", throwable);
        return new Result(Result.ResultCode.FAIL, "系统异常", null);
    }
}
